import dict from './dict'

export default {
  namespaced: true,
  state: {
    // 是否已经初始化数据
    init: false,
    // 初始化错误文本
    initText: '',
    // 用户默认主页
    home: 'home',
    // 用户ID
    id: '',
    // 用户名称
    name: '',
    // 用户头像地址
    headSrc: '',
    // 权限列表
    permList: [],
    // 字典列表
    dictList: {},
    // 字典取值类型
    dictDbList: {},
    // 前端私有字典列表
    dictListPrivate: dict,
    // 用户详细信息
    detailInfo: {}
  },
  mutations: {
    updateInit(state, bool) {
      state.init = bool
    },
    updateInitText(state, text) {
      state.initText = text
    },
    updateHome(state, val) {
      state.home = val
    },
    updateId(state, id) {
      state.id = id
    },
    updateName(state, name) {
      state.name = name
    },
    updateHeadSrc(state, headSrc) {
      state.headSrc = headSrc
    },
    updatePermList(state, permList) {
      state.permList = permList
    },
    updateDictList(state, dictList = []) {
      var dict = {}
      for (var i = 0; i < dictList.length; i++) {
        dict[dictList[i].dictType] = {}
        for (var u = 0; u < dictList[i].sysDictDataDTOS.length; u++) {
          dict[dictList[i].dictType][dictList[i].sysDictDataDTOS[u].dictKey] = dictList[i].sysDictDataDTOS[u].dictTag
        }
      }
      state.dictList = dict
    },
    updateDictDbList(state, dictList = []) {
      var dict = {}
      for (var i = 0; i < dictList.length; i++) {
        dict[dictList[i].dictType] = {}
        for (var u = 0; u < dictList[i].sysDictDataDTOS.length; u++) {
          dict[dictList[i].dictType][dictList[i].sysDictDataDTOS[u].dictKey] = dictList[i].sysDictDataDTOS[
            u
          ].cmntStr.split('|')[0]
        }
      }
      state.dictDbList = dict
    },
    updateDetailInfo(state, info) {
      state.detailInfo = info
    }
  }
}
